﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.PopupSceneSkeletonAnimationScript
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using TaleWorlds.DotNet;
using TaleWorlds.Engine;
using TaleWorlds.Library;

#nullable disable
namespace TaleWorlds.MountAndBlade.View
{
  public class PopupSceneSkeletonAnimationScript : ScriptComponentBehavior
  {
    public string SkeletonName = "";
    public int BoneIndex;
    public Vec3 AttachmentOffset = new Vec3();
    public string InitialAnimationClip = "";
    public string PositiveAnimationClip = "";
    public string NegativeAnimationClip = "";
    public string InitialAnimationContinueClip = "";
    public string PositiveAnimationContinueClip = "";
    public string NegativeAnimationContinueClip = "";
    private int _currentState;

    protected override void OnInit()
    {
      base.OnInit();
      this.SetScriptComponentToTick(this.GetTickRequirement());
    }

    public void Initialize()
    {
      if (this.SkeletonName != "" && ((NativeObject) this.GameEntity.Skeleton == (NativeObject) null || this.GameEntity.Skeleton.GetName() != this.SkeletonName))
      {
        this.GameEntity.CreateSimpleSkeleton(this.SkeletonName);
      }
      else
      {
        if (!(this.SkeletonName == "") || !((NativeObject) this.GameEntity.Skeleton != (NativeObject) null))
          return;
        this.GameEntity.RemoveSkeleton();
      }
    }

    public override ScriptComponentBehavior.TickRequirement GetTickRequirement()
    {
      return ScriptComponentBehavior.TickRequirement.Tick;
    }

    protected override void OnTick(float dt)
    {
      if (this.GameEntity.Skeleton.GetAnimationAtChannel(0) == this.InitialAnimationClip && (double) this.GameEntity.Skeleton.GetAnimationParameterAtChannel(0) >= 1.0)
        this.GameEntity.Skeleton.SetAnimationAtChannel(this.InitialAnimationContinueClip, 0);
      if (this.GameEntity.Skeleton.GetAnimationAtChannel(0) == this.PositiveAnimationClip && (double) this.GameEntity.Skeleton.GetAnimationParameterAtChannel(0) >= 1.0)
        this.GameEntity.Skeleton.SetAnimationAtChannel(this.PositiveAnimationContinueClip, 0);
      if (!(this.GameEntity.Skeleton.GetAnimationAtChannel(0) == this.NegativeAnimationClip) || (double) this.GameEntity.Skeleton.GetAnimationParameterAtChannel(0) < 1.0)
        return;
      this.GameEntity.Skeleton.SetAnimationAtChannel(this.NegativeAnimationContinueClip, 0);
    }

    public void SetState(int state)
    {
      string str;
      switch (state)
      {
        case 0:
          str = this.InitialAnimationClip;
          break;
        case 1:
          str = this.PositiveAnimationClip;
          break;
        default:
          str = this.NegativeAnimationClip;
          break;
      }
      string animationName = str;
      if ((NativeObject) this.GameEntity?.Skeleton != (NativeObject) null && !string.IsNullOrEmpty(animationName))
        this.GameEntity.Skeleton.SetAnimationAtChannel(animationName, 0);
      this._currentState = state;
    }
  }
}
